package com.learn.base;

import com.learn.emuns.LearnResultEnums;
import com.learn.emuns.ProductStatusEnums;

import java.io.Serializable;

public class ApiResultUtils
{
	public static <T extends Serializable> ApiResult<T> build (String status, String errMsg, T data)
	{
		ApiResult<T> apiResult = new ApiResult<> ();
		Header header = new Header ();
		header.setStatus (status);
		header.setErrMsg (errMsg);
		apiResult.setHeader (header);
		apiResult.setData (data);
		return apiResult;
	}

	public static <T extends Serializable> ApiResult<T> buildSuccess (T data)
	{
		ApiResult<T> apiResult = new ApiResult<> ();
		Header header = new Header ();
		header.setStatus (LearnResultEnums.SUCCESS.getStatus ());
		header.setErrMsg (LearnResultEnums.SUCCESS.getErrMsg ());
		apiResult.setHeader (header);
		apiResult.setData (data);
		return apiResult;
	}

	public static <T extends Serializable> ApiResult<T> fail (String errMsg){
		ApiResult<T> apiResult = new ApiResult<> ();
		Header header = new Header ();
		header.setErrMsg (errMsg);
		apiResult.setHeader (header);
		return apiResult;
	}
}
